//------------------------------------------------------------------------------
// <pcdd-entitiy>
//     彩票主流业务类库
//     模版配置业务对象
// </pcdd-entitiy>
//------------------------------------------------------------------------------ 

using CL.Enum.Common;
using CL.Game.DAL;
using CL.Game.Entity;
using System.Collections.Generic;
using CL.Redis.BLL;
using System.Linq;

namespace CL.Game.BLL
{

    /// <summary>
    /// TemplateConfigBLL 业务
    /// </summary>
    public class TemplateConfigBLL
    {
        TemplateConfigDAL dal = new TemplateConfigDAL(DbConnectionEnum.CaileGame);
        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(long ID)
        {
            return dal.Exists(ID);
        }
        /// <summary>
        /// 插入对象
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public int InsertEntity(TemplateConfigEntity entity)
        {
            return dal.InsertEntity(entity);
        }
        /// <summary>
        /// 修改对象
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public int ModifyEntity(TemplateConfigEntity entity)
        {
            return dal.ModifyEntity(entity);
        }
        /// <summary>
        /// 获取对象
        /// </summary>
        /// <param name="ID"></param>
        /// <returns></returns>
        public TemplateConfigEntity QueryEntity(int ID)
        {
            return dal.QueryEntity(ID);
        }

        /// <summary>
        /// 获取所有对象
        /// </summary>
        /// <returns></returns>
        public List<TemplateConfigEntity> QueryEntitys()
        {
            return dal.QueryEntitys();
        }
        public List<TemplateConfigEntity> QueryEntitys(byte TemplateType)
        {
            return dal.GetList(new { TemplateType = TemplateType }, "ID desc").ToList();
        }
        /// <summary>
        /// 删除对象
        /// </summary>
        /// <param name="ID"></param>
        /// <returns></returns>
        public bool DelEntity(long ID)
        {
            return dal.DelEntity(ID);
        }
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public List<TemplateConfigEntity> QueryListByPage(string strName, int TemplateType, string orderby, int pageSize, int pageIndex, ref int recordCount)
        {
            return dal.QueryListByPage(strName, TemplateType, orderby, pageSize, pageIndex, ref recordCount);
        }


        #region 自定义方法
        /// <summary>
        /// 查询
        /// </summary>
        /// <returns></returns>
        public string QueryWinMoneyPushTemplate()
        {
            try
            {
                //中奖推送
                var EntityRedis = new BusinessRedis().QueryTemplateConfigEntityRedis(4, 5);
                if (EntityRedis == null)
                {
                    EntityRedis = this.QueryEntity(5);
                    if (EntityRedis != null)
                        new BusinessRedis().TemplateConfigEntityRedis(EntityRedis);
                }
                if (EntityRedis == null)
                    return "";
                else
                    return EntityRedis.TemplateContent;
            }
            catch
            {
                throw;
            }
        }
        /// <summary>
        /// 中奖公告
        /// </summary>
        /// <returns></returns>
        public string QueryWinAwardNotice()
        {
            try
            {
                //中奖推送
                var EntityRedis = new BusinessRedis().QueryTemplateConfigEntityRedis(1, 7);
                if (EntityRedis == null)
                {
                    EntityRedis = this.QueryEntity(7);
                    if (EntityRedis != null)
                        new BusinessRedis().TemplateConfigEntityRedis(EntityRedis);
                }
                if (EntityRedis == null)
                    return "";
                else
                    return EntityRedis.TemplateContent;
            }
            catch
            {
                throw;
            }
        }
        /// <summary>
        /// 查询撤单推送模板
        /// </summary>
        /// <returns></returns>
        public string QueryRevokePushTemplate()
        {
            try
            {
                //中奖推送
                var EntityRedis = new BusinessRedis().QueryTemplateConfigEntityRedis(4, 6);
                if (EntityRedis == null)
                {
                    EntityRedis = this.QueryEntity(6);
                    if (EntityRedis != null)
                        new BusinessRedis().TemplateConfigEntityRedis(EntityRedis);
                }
                if (EntityRedis == null)
                    return "";
                else
                    return EntityRedis.TemplateContent;
            }
            catch
            {
                throw;
            }
        }
        /// <summary>
        /// 彩券过期提醒模板
        /// </summary>
        /// <returns></returns>
        public string QueryCouponsExpireTime()
        {
            try
            {
                //中奖推送
                var EntityRedis = new BusinessRedis().QueryTemplateConfigEntityRedis(4, 8);
                if (EntityRedis == null)
                {
                    EntityRedis = this.QueryEntity(8);
                    if (EntityRedis != null)
                        new BusinessRedis().TemplateConfigEntityRedis(EntityRedis);
                }
                if (EntityRedis == null)
                    return "";
                else
                    return EntityRedis.TemplateContent;
            }
            catch
            {
                throw;
            }
        }

        /// <summary>
        /// 消息推送
        /// </summary>
        /// <returns></returns>
        public List<TemplateConfigEntity> QueryIssuePush()
        {
            try
            {
                var Entitys = new BusinessRedis().QueryTemplateConfigEntityRedis(5);
                if (Entitys == null)
                {
                    Entitys = this.QueryEntitys(5);
                    if (Entitys != null)
                        foreach (var item in Entitys)
                            new BusinessRedis().TemplateConfigEntityRedis(item);
                }
                return Entitys;
            }
            catch
            {
                throw;
            }
        }
        #endregion
    }
}
